package _designPatterm.单例模式.饿汉式;

/**
 * 饿汉式:静态代码块
 * 可用,但会造成内存浪费
 */
public class singletonTest02 {
    public static void main(String[] args) {
        Singleton2 instance1 = Singleton2.getInstance2();
        Singleton2 instance2 = Singleton2.getInstance2();
        System.out.println(instance2 == instance1);
    }
}

class Singleton2 {
    private Singleton2() {
    }

    private static Singleton2 instance2;

    static {
        instance2 = new Singleton2();
    }

    static Singleton2 getInstance2() {
        return instance2;
    }

}
